package com.example.scaloovka;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class EditActivity extends Activity {

	protected static final String TAG = "ScaloovkaEdit";
	private EditText[] scales;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_edit);
		EditText scale1 = (EditText) findViewById(R.id.edit1);
		EditText scale2 = (EditText) findViewById(R.id.edit2);
		EditText scale3 = (EditText) findViewById(R.id.edit3);
		EditText scale4 = (EditText) findViewById(R.id.edit4);
		this.scales = new EditText[] { scale1, scale2, scale3, scale4 };
		updateScales();
	}

	@Override
	protected void onResume() {
		super.onResume();
		updateScales();
	}

	private void updateScales() {
		double[] scaleVals = ScalesMap.getInstance().getScales();
		for (int i = 0; i < this.scales.length; i++) {
			this.scales[i].setText(String.valueOf(scaleVals[i]));
		}
	}

	public void saveAction(View view) {
		Log.d(TAG, "Action save chosen");
		double[] scalesInputs = new double[this.scales.length];
		for (int i = 0; i < this.scales.length; i++) {
			scalesInputs[i] = Double.parseDouble(this.scales[i].getText()
					.toString());
		}
		ScalesMap.getInstance().setScales(scalesInputs);
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
	}
}
